package openmarket.web;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import openmarket.dao.PageDAO;
import openmarket.dao.UserDAO;
import openmarket.dao.dataobject.UserDO;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class HelloController implements Controller {

	protected final Log logger = LogFactory.getLog(getClass());
	private PageDAO pageDAO;
	private UserDAO userDAO;

	public void setPageDAO(PageDAO pageDAO) {
		this.pageDAO = pageDAO;
	}

	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}

	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		UserDO user = null;
		try {
			user = userDAO.getUserByName("langzhongfeng");
		} catch (SQLException e) {
			logger.error(e.getMessage());
		}
		List list = new ArrayList();
		list.add(user);
		return new ModelAndView("test", "list", list);
	}
}
